package com.ruoyi.hospital.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.PrescriptionDetail;
import com.ruoyi.hospital.service.IPrescriptionDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 处方明细Controller
 * 
 * @author qichi
 * @date 2023-07-05
 */
@RestController
@RequestMapping("/hospital/PrescriptionDetail")
public class PrescriptionDetailController extends BaseController
{
    @Autowired
    private IPrescriptionDetailService prescriptionDetailService;

    /**
     * 查询处方明细列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:PrescriptionDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrescriptionDetail prescriptionDetail)
    {
        startPage();
        List<PrescriptionDetail> list = prescriptionDetailService.selectPrescriptionDetailList(prescriptionDetail);
        return getDataTable(list);
    }

    /**
     * 导出处方明细列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:PrescriptionDetail:export')")
    @Log(title = "处方明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PrescriptionDetail prescriptionDetail)
    {
        List<PrescriptionDetail> list = prescriptionDetailService.selectPrescriptionDetailList(prescriptionDetail);
        ExcelUtil<PrescriptionDetail> util = new ExcelUtil<PrescriptionDetail>(PrescriptionDetail.class);
        util.exportExcel(response, list, "处方明细数据");
    }

    /**
     * 获取处方明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:PrescriptionDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(prescriptionDetailService.selectPrescriptionDetailById(id));
    }

    /**
     * 新增处方明细
     */
    @PreAuthorize("@ss.hasPermi('hospital:PrescriptionDetail:add')")
    @Log(title = "处方明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrescriptionDetail prescriptionDetail)
    {
        return toAjax(prescriptionDetailService.insertPrescriptionDetail(prescriptionDetail));
    }

    /**
     * 修改处方明细
     */
    @PreAuthorize("@ss.hasPermi('hospital:PrescriptionDetail:edit')")
    @Log(title = "处方明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrescriptionDetail prescriptionDetail)
    {
        return toAjax(prescriptionDetailService.updatePrescriptionDetail(prescriptionDetail));
    }

    /**
     * 删除处方明细
     */
    @PreAuthorize("@ss.hasPermi('hospital:PrescriptionDetail:remove')")
    @Log(title = "处方明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(prescriptionDetailService.deletePrescriptionDetailByIds(ids));
    }
}
